Squirrel Eating Pizza!
Squirrel Eating Pizza!

The purpose of Portfolio Piece 1 is to create interactive maps using the mapview package. In fall of 2020, my friend sent me a picture of a squirrel eating a large piece of pizza up in a tree. As many people consider New York City the place for pizza, I am interested to see how the location of squirrel sightings in Central Park and pizza restaurants. Further, I want to see if squirrels were spotted more frequently eating near pizza restaurants.

Data Credits

Data from NYC Squirrel Census. Retrieved from jonthegeek originally shared by Sara Stoudt. Pizza Data

Load squirrel data and packages

library(tidyverse) 
nyc_squirrels <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2019/2019-10-29/nyc_squirrels.csv")
## Rows: 3023 Columns: 36
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (14): unique_squirrel_id, hectare, shift, age, primary_fur_color, highli...
## dbl  (9): long, lat, date, hectare_squirrel_number, zip_codes, community_dis...
## lgl (13): running, chasing, climbing, eating, foraging, kuks, quaas, moans, ...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Squirrel fur color visualization

ggplot(data=nyc_squirrels, aes(x=primary_fur_color, fill = primary_fur_color)) + 
  geom_bar(stat = "count", width = 1) + 
  scale_fill_manual(values = c("black", "chocolate4","darkgrey")) + 
  labs(title="NYC Squirrel Fur Color", 
       xlab = "Number of Observations", 
       ylab = "Fur Color")

This visualization utilizes the scale_fill_manual function in order to customize the colors of the bars to match the fur color they represent.

Load pizza data

pizza_datafiniti <- readr::read_csv("https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2019/2019-10-01/pizza_datafiniti.csv")
## Rows: 10000 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): name, address, city, country, province, categories
## dbl (4): latitude, longitude, price_range_min, price_range_max
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pizza_nyc <- pizza_datafiniti %>%
  filter(city == "New York")
names(pizza_nyc)[names(pizza_nyc) == 'longitude'] <- 'long'
names(pizza_nyc)[names(pizza_nyc) == 'latitude'] <- 'lat'

Combine squirrel and pizza data

nyc_squirrels <- nyc_squirrels %>% 
  mutate(source = "squirrels")
pizza_nyc <- pizza_nyc %>% 
  mutate(source = "pizza")
squirrels_and_pizza <- bind_rows(nyc_squirrels, pizza_nyc)
print(squirrels_and_pizza)
## # A tibble: 3,678 × 45
##     long   lat unique_squirrel_id hectare shift     date hectare_squirrel_number
##    <dbl> <dbl> <chr>              <chr>   <chr>    <dbl>                   <dbl>
##  1 -74.0  40.8 37F-PM-1014-03     37F     PM    10142018                       3
##  2 -74.0  40.8 37E-PM-1006-03     37E     PM    10062018                       3
##  3 -74.0  40.8 2E-AM-1010-03      02E     AM    10102018                       3
##  4 -74.0  40.8 5D-PM-1018-05      05D     PM    10182018                       5
##  5 -74.0  40.8 39B-AM-1018-01     39B     AM    10182018                       1
##  6 -74.0  40.8 33H-AM-1019-02     33H     AM    10192018                       2
##  7 -74.0  40.8 6G-PM-1020-02      06G     PM    10202018                       2
##  8 -74.0  40.8 35C-PM-1013-03     35C     PM    10132018                       3
##  9 -74.0  40.8 7B-AM-1008-09      07B     AM    10082018                       9
## 10 -74.0  40.8 32E-PM-1017-14     32E     PM    10172018                      14
## # ℹ 3,668 more rows
## # ℹ 38 more variables: age <chr>, primary_fur_color <chr>,
## #   highlight_fur_color <chr>,
## #   combination_of_primary_and_highlight_color <chr>, color_notes <chr>,
## #   location <chr>, above_ground_sighter_measurement <chr>,
## #   specific_location <chr>, running <lgl>, chasing <lgl>, climbing <lgl>,
## #   eating <lgl>, foraging <lgl>, other_activities <chr>, kuks <lgl>, …

NYC Squirrel sightings and pizza restuarant plot.

ggplot(squirrels_and_pizza) + 
  geom_point(mapping = aes(x = long, y = lat,
  color = source)) + 
  labs(
    title= "New York City Pizza Restaurant Locations and Squirrel Sightings",
    x = "Longitude", 
    y = "Latitude"
    )

Install “sf” package in the R console by entering install.packages(“sf”). Install “terra” package by entering “install.packages(”terra) in the R console.

library(tidyverse)
library(sf)
## Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(mapview)
mapview(squirrels_and_pizza, xcol = "long", ycol = "lat", crs = 4269, grid = FALSE, zcol = "source", legend = TRUE)

Filter Data for only squirrels sighted eating

library(dplyr)
eating_squirrels <- nyc_squirrels %>% 
  filter(eating == "TRUE")

Combine data of squirrels sighted eating and pizza locations

squirrels_eating_and_pizza <- bind_rows(eating_squirrels, pizza_nyc)
print(squirrels_eating_and_pizza)
## # A tibble: 1,415 × 45
##     long   lat unique_squirrel_id hectare shift     date hectare_squirrel_number
##    <dbl> <dbl> <chr>              <chr>   <chr>    <dbl>                   <dbl>
##  1 -74.0  40.8 32E-PM-1017-14     32E     PM    10172018                      14
##  2 -74.0  40.8 16C-PM-1018-03     16C     PM    10182018                       3
##  3 -74.0  40.8 32A-PM-1013-03     32A     PM    10132018                       3
##  4 -74.0  40.8 29I-PM-1007-01     29I     PM    10072018                       1
##  5 -74.0  40.8 7E-AM-1006-02      07E     AM    10062018                       2
##  6 -74.0  40.8 17C-PM-1013-05     17C     PM    10132018                       5
##  7 -74.0  40.8 38C-PM-1014-09     38C     PM    10142018                       9
##  8 -74.0  40.8 8H-AM-1017-06      08H     AM    10172018                       6
##  9 -74.0  40.8 19D-AM-1007-01     19D     AM    10072018                       1
## 10 -74.0  40.8 3E-PM-1008-07      03E     PM    10082018                       7
## # ℹ 1,405 more rows
## # ℹ 38 more variables: age <chr>, primary_fur_color <chr>,
## #   highlight_fur_color <chr>,
## #   combination_of_primary_and_highlight_color <chr>, color_notes <chr>,
## #   location <chr>, above_ground_sighter_measurement <chr>,
## #   specific_location <chr>, running <lgl>, chasing <lgl>, climbing <lgl>,
## #   eating <lgl>, foraging <lgl>, other_activities <chr>, kuks <lgl>, …

Interactive map for squirrels sighted eating and pizza locations

library(tidyverse)
library(sf)
library(mapview)
mapview(squirrels_eating_and_pizza, xcol = "long", ycol = "lat", crs = 4269, grid = FALSE, zcol = "source", legend = TRUE, alpha = .20)

Interpretation

Given the interactive map, there is not a clear cluster of squirrels spotted feeding near pizza restaurants. This could be due many factors such as the relatively restricted size of Central Park, a multitude of food options for squirrels.